<template>
    <div class="front bj">
        <el-scrollbar style="height: 100%;">
            <el-form :model="formData" label-width="120px" label-position="left" ref="formRef" status-icon :rules="formRules">
                <el-form-item label="名称：" prop="name">
                    <el-input v-model.trim="formData.name" @keyup.enter.native="enterKey($event, 'MA1')"></el-input>
                </el-form-item>
                <el-form-item label="助记码：" prop="mnemonicCode">
                    <el-input v-model.trim="formData.mnemonicCode" ref="MA1" @keyup.enter.native="enterKey($event, 'MA2')"></el-input>
                </el-form-item>
                <el-form-item label="简称：" prop="abbreviation">
                    <el-input v-model.trim="formData.abbreviation" ref="MA2" @keyup.enter.native="enterKey($event, 'MA3')"></el-input>
                </el-form-item>
                <el-form-item label="客户地址：" prop="address">
                    <el-input v-model.trim="formData.address" ref="MA3" @keyup.enter.native="enterKey($event, 'MA4')"></el-input>
                </el-form-item>
                <el-form-item label="区域：" prop="location">
                    <el-select v-model="formData.location" clearable filterable  ref="MA4" @keyup.enter.native="enterKey($event, 'MA5')" placeholder="选择区域" style="width: 100%;">
                        <el-option v-for="item in locationList"  :label="item.detailedName" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="行业：" prop="trade">
                    <el-select v-model="formData.trade" clearable filterable ref="MA5" @keyup.enter.native="enterKey($event, 'MA6')" placeholder="选择行业" style="width: 100%;">
                        <el-option v-for="item in tradeList"  :label="item.icName" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="联系人：" prop="linkman">
                    <el-input v-model.trim="formData.linkman" ref="MA6" @keyup.enter.native="enterKey($event, 'MA7')"></el-input>
                </el-form-item>
                <el-form-item label="电话：" prop="tel">
                    <el-input v-model.trim="formData.tel" ref="MA7" @keyup.enter.native="enterKey($event, 'MA8')"></el-input>
                </el-form-item>
                <el-form-item label="传真：" prop="fax">
                    <el-input v-model.trim="formData.fax" ref="MA8" @keyup.enter.native="enterKey($event, 'MA9')"></el-input>
                </el-form-item>
                <el-form-item label="客户大类：" prop="clientCategoryId">
                    <el-select v-model="formData.clientCategoryId" placeholder="选择客户大类" style="width: 100%;">
                        <el-option v-for="item in customerTypeList" :label="item.name" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="客户价值分类：" prop="customerValueCategory">
                    <el-select v-model="formData.customerValueCategory" clearable filterable ref="MA10" @keyup.enter.native="enterKey($event, 'MA11')" placeholder="选择客户价值分类" style="width: 100%;">
                        <el-option v-for="item in customerValueCategoryList"  :label="item.name" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="客户产品分类：" prop="customerProductCategory">
                    <el-select v-model="formData.customerProductCategory" clearable filterable ref="MA11" @keyup.enter.native="enterKey($event, 'MA12')" placeholder="选择客户产品分类" style="width: 100%;">
                        <el-option v-for="item in customerProductCategoryList"  :label="item.name" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="开户名1" prop="accountNameOne" class="check">
                    <el-input v-model.trim="formData.accountNameOne" ref="MA12" @keyup.enter.native="enterKey($event, 'MA13')"></el-input>
                </el-form-item>
                <el-form-item label="开户银行1" prop="depositBankOne" class="check">
                    <el-input v-model.trim="formData.depositBankOne" ref="MA13" @keyup.enter.native="enterKey($event, 'MA14')"></el-input>
                </el-form-item>
                <el-form-item label="银行账户1" prop="bankAccountOne" class="check">
                    <el-input v-model.trim="formData.bankAccountOne" ref="MA14" @keyup.enter.native="enterKey($event, 'MA15')"></el-input>
                </el-form-item>
                <el-form-item label="开户名2" prop="accountNameTwo">
                    <el-input v-model.trim="formData.accountNameTwo" ref="MA15" @keyup.enter.native="enterKey($event, 'MA16')"></el-input>
                </el-form-item>
                <el-form-item label="开户银行2" prop="depositBankTwo">
                    <el-input v-model.trim="formData.depositBankTwo" ref="MA16" @keyup.enter.native="enterKey($event, 'MA17')"></el-input>
                </el-form-item>
                <el-form-item label="银行账户2" prop="bankAccountTwo">
                    <el-input v-model.trim="formData.bankAccountTwo" ref="MA17" @keyup.enter.native="enterKey($event, 'MA18')"></el-input>
                </el-form-item>
                <el-form-item label="开户名3" prop="accountNameThree">
                    <el-input v-model.trim="formData.accountNameThree" ref="MA18" @keyup.enter.native="enterKey($event, 'MA19')"></el-input>
                </el-form-item>
                <el-form-item label="开户银行3" prop="depositBankThree">
                    <el-input v-model.trim="formData.depositBankThree" ref="MA19" @keyup.enter.native="enterKey($event, 'MA20')"></el-input>
                </el-form-item>
                <el-form-item label="银行账户3" prop="bankAccountThree">
                    <el-input v-model.trim="formData.bankAccountThree" ref="MA20" @keyup.enter.native="enterKey($event, 'MA21')"></el-input>
                </el-form-item>
                <el-form-item label="税务登记号：" prop="taxRedistrationNumber">
                    <el-input v-model.trim="formData.taxRedistrationNumber" ref="MA21" @keyup.enter.native="enterKey($event, 'MA22')"></el-input>
                </el-form-item>
                <el-form-item label="税率：" prop="vatRates">
                    <el-select v-model="formData.vatRates" clearable filterable ref="MA22" @keyup.enter.native="enterKey($event, 'MA23')" placeholder="选择税率" style="width: 100%;">
                        <el-option v-for="item in vatRatesList"  :label="item.detailedName" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="所在国家：" prop="locationCountryId">
                    <el-select v-model="formData.locationCountryId" ref="MA25" @keyup.enter.native="enterKey($event, 'MA26')" placeholder="选择国家" style="width: 100%;">
                        <el-option v-for="item in countryList"  :label="item.name" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="所在省份：" prop="locationProvinceId">
                    <el-select v-model="formData.locationProvinceId" ref="MA24" @keyup.enter.native="enterKey($event, 'MA25')" placeholder="选择省份" style="width: 100%;">
                        <el-option v-for="item in provinceList"  :label="item.name" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="所在城市：" prop="locationCityId">
                    <el-select v-model="formData.locationCityId" ref="MA23" @keyup.enter.native="enterKey($event, 'MA24')" placeholder="选择城市" style="width: 100%;">
                        <el-option v-for="item in cityList"  :label="item.name" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="公司主页：" prop="homepage">
                    <el-input v-model="formData.homepage" ref="MA26" placeholder="http(s)://www.xxxx.xx" @keyup.enter.native="enterKey($event, 'MA27')">
                        <el-button slot="append" style="padding: 12px !important;" title="跳转" @click="toHomePage">
                            <img src="../../../assets/images/gobackto.png" alt="">
                        </el-button>
                    </el-input>
                </el-form-item>
                <el-form-item label="法人代表：" prop="legalPersonRepresentative">
                    <el-input v-model.trim="formData.legalPersonRepresentative" ref="MA27" @keyup.enter.native="enterKey($event, 'MA28')"></el-input>
                </el-form-item>
                <el-form-item label="销售方式：" prop="saleMethod">
                    <el-select v-model="formData.saleMethod" clearable ref="MA28" @keyup.enter.native="enterKey($event, 'MA29')" placeholder="选择销售方式" style="width: 100%;">
                        <el-option v-for="item in saleMethodList" :label="item.detailedName" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="分管部门：" prop="chargeDepartment">
                    <el-input v-model.trim="charge[0]" readonly @keyup.enter.native="enterKey($event, 'MA30')" @click.native="showDepartment"></el-input>
                    <el-input v-model.trim="formData.chargeDepartment" readonly style="display: none;"></el-input>
                </el-form-item>
                <el-form-item label="专营业务员：" prop="franchiseClerk">
                    <el-select v-model="formData.franchiseClerk" ref="MA30" @keyup.enter.native="enterKey($event, 'MA31')" placeholder="选择专营业务员" style="width: 100%;">
                        <el-option v-for="item in franchiseClerkList"  :label="item.name" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="信用额度：" prop="creditAmount">
                    <el-input v-model.trim="formData.creditAmount" ref="MA31" @keyup.enter.native="enterKey($event, 'MA32')"></el-input>
                </el-form-item>
                <el-form-item label="结算期限：" prop="settlementPeriod">
                    <el-select v-model="formData.settlementPeriod" ref="MA32" @keyup.enter.native="enterKey($event, 'MA33')" placeholder="选择结算期限" style="width: 100%;">
                        <el-option v-for="item in settlementPeriodList"  :label="item.detailedName" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="备注：" prop="remark">
                    <el-input v-model.trim="formData.remark" ref="MA33" @keyup.enter.native="save('formRef')"></el-input>
                </el-form-item>
                <el-form-item label="连续增加：" style="margin-bottom: 5px !important;" v-if="!rowId">
                    <el-checkbox v-model="continueAdd"></el-checkbox>
                </el-form-item>
                <el-form-item style="margin-bottom: 10px !important;">
                    <el-button type="primary" size="small" @click="save('formRef')">保存</el-button>
                    <el-button type="danger" size="small" @click="close">离开</el-button>
                </el-form-item>
            </el-form>
        </el-scrollbar>
    </div>
</template>
<script>
export default {
    data() {
        let checkAccountNameOne = (rule, value, callback) => {          //如果开户名1有值，那么开户银行1和银行账户1必须有值
            this.$refs.formRef.validateField('depositBankOne');
            callback();
        }
        let checkDepositBankOne = (rule, value, callback) => {          //如果开户银行1有值，那么银行账户1必须有值
            if(this.formData['accountNameOne']) {
                if(!value) {
                    callback(new Error('开户银行1不能为空'));
                } else {
                    this.$refs.formRef.validateField('bankAccountOne');
                    callback();
                }
            } else {
                this.$refs.formRef.validateField('bankAccountOne');
                callback();
            }
        }
        let checkBankAccountOne = (rule, value, callback) => {          //校验银行账户1
            if(this.formData['depositBankOne']) {
                if(!value) {
                    callback(new Error('银行账户1不能为空'));
                } else if(!/^[0-9]+$/.test(value)) {
                    callback(new Error('只能输入数字'));
                } else {
                    callback();
                }
            } else {
                if(value) {
                    if(!/^[0-9]+$/.test(value)) {
                        callback(new Error('只能输入数字'));
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        }

        let checkAccountNameTwo = (rule, value, callback) => {          //如果开户名2有值，那么开户银行2和银行账户2必须有值
            this.$refs.formRef.validateField('depositBankTwo');
            callback();
        }
        let checkDepositBankTwo = (rule, value, callback) => {          //如果开户银行2有值，那么银行账户2必须有值
            if(this.formData['accountNameTwo']) {
                if(!value) {
                    callback(new Error('开户银行2不能为空'));
                } else {
                    this.$refs.formRef.validateField('bankAccountTwo');
                    callback();
                }
            } else {
                this.$refs.formRef.validateField('bankAccountTwo');
                callback();
            }
        }
        let checkBankAccountTwo = (rule, value, callback) => {          //校验银行账户2
            if(this.formData['depositBankTwo']) {
                if(!value) {
                    callback(new Error('银行账户2不能为空'));
                } else if(!/^[0-9]+$/.test(value)) {
                    callback(new Error('只能输入数字'));
                } else {
                    callback();
                }
            } else {
                if(value) {
                    if(!/^[0-9]+$/.test(value)) {
                        callback(new Error('只能输入数字'));
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        }

        let checkAccountNameThree = (rule, value, callback) => {          //如果开户名3有值，那么开户银行2和银行账户3必须有值
            this.$refs.formRef.validateField('depositBankThree');
            callback();
        }
        let checkDepositBankThree = (rule, value, callback) => {          //如果开户银行3有值，那么银行账户3必须有值
            if(this.formData['accountNameThree']) {
                if(!value) {
                    callback(new Error('开户银行3不能为空'));
                } else {
                    this.$refs.formRef.validateField('bankAccountThree');
                    callback();
                }
            } else {
                this.$refs.formRef.validateField('bankAccountThree');
                callback();
            }
        }
        let checkBankAccountThree = (rule, value, callback) => {          //校验银行账户3
            if(this.formData['depositBankThree']) {
                if(!value) {
                    callback(new Error('银行账户3不能为空'));
                } else if(!/^[0-9]+$/.test(value)) {
                    callback(new Error('只能输入数字'));
                } else {
                    callback();
                }
            } else {
                if(value) {
                    if(!/^[0-9]+$/.test(value)) {
                        callback(new Error('只能输入数字'));
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        }
        let checkTel = (rule, value, callback) => {     //校验电话
            if(value) {
                if(!/^[0-9]+$/.test(value)) {
                    callback(new Error('只能输入数字'));
                } else {
                    callback();
                }
            } else {
                callback();
            }
        }
        let checkFax = (rule, value, callback) => {         //校验传真
            if(value) {
                if(!/^[0-9]+$/.test(value)) {
                    callback(new Error('只能输入数字'));
                } else {
                    callback();
                }
            } else {
                callback();
            }
        }
        let checkCreditAmount = (rule, value, callback) => {        //校验信用额度
            if(value) {
                if(!/^[0-9]+$/.test(value)) {
                    callback(new Error('只能输入数字'));
                } else {
                    callback();
                }
            } else {
                callback();
            }
        }
        return {
            continueAdd: false,
            formData: {
                clientCategoryId: '',
                chargeDepartment: ''
            },
            formRules: {
                name: [{required: true, message: '名称不能为空', triggle: 'blur'}],
                linkman: [{required: true, message: '联系人不能为空', triggle: 'blur'}],
                clientCategoryId: [{required: true, message: '选择客户大类', triggle: 'change', type: 'number'}],
                accountNameOne: [{validator: checkAccountNameOne, trigger: 'blur'}],
                depositBankOne: [{validator: checkDepositBankOne, trigger: 'blur'}],
                bankAccountOne: [{validator: checkBankAccountOne, trigger: 'blur'}],
                accountNameTwo: [{validator: checkAccountNameTwo, trigger: 'blur'}],
                depositBankTwo: [{validator: checkDepositBankTwo, trigger: 'blur'}],
                bankAccountTwo: [{validator: checkBankAccountTwo, trigger: 'blur'}],
                accountNameThree: [{validator: checkAccountNameThree, trigger: 'blur'}],
                depositBankThree: [{validator: checkDepositBankThree, trigger: 'blur'}],
                bankAccountThree: [{validator: checkBankAccountThree, trigger: 'blur'}],
                tel: [{validator: checkTel, triggle: 'blur'}],
                fax: [{validator: checkFax, triggle: 'blur'}],
                creditAmount: [{validator: checkCreditAmount, triggle: 'blur'}]
            },
            locationList: [],                   //区域
            tradeList: [],                      //行业
            customerTypeList: [],               //客户大类
            customerValueCategoryList: [],      //客户价值分类
            customerProductCategoryList: [],    //客户产品分类
            vatRatesList: [],                   //税率
            countryList: [],                    //国家
            provinceList: [],                   //省份
            cityList: [],                       //区域
            saleMethodList: [],                 //销售方式
            charge: this.$store.state.customerStore.parentName,      //分管部门名称
            parentId: this.$store.state.customerStore.parentId,     //分管部门id
            franchiseClerkList: [],             //专营业务员
            settlementPeriodList: [],           //结算期限
            countryName: '',        //国家名称
            provinceName: '',       //省份名称
            cityName: '',           //城市名称
        }
    },
    watch: {
        'formData.locationCountryId'(newVal, oldVal) {
            if(oldVal && (newVal != oldVal)) {
                this.formData['locationProvinceId'] = '';         //清空省份数据
                this.formData['locationCityId'] = '';            //清空城市数据
                this.provinceList.length = 0;
                this.cityList.length = 0;
            }
            this.getProvinceList(newVal);
        },
        'formData.locationProvinceId'(newVal, oldVal) {
            if(oldVal && (newVal != oldVal)) {
                this.formData['locationCityId'] = '';            //清空城市数据
                this.cityList.length = 0;
            }
            this.getCityList(newVal);
        },
        parentId(newVal) {      //监听分管部门变化，实时更新分管部门id
            this.formData['chargeDepartment'] = newVal[0];
        }
    },
    computed: {
        systemId() {        //系统id
            return this.$store.state.systemId;
        },
        rowId() {
            return this.$store.state.customerStore.rowId;
        }
    },
    methods: {
        getUpdateData() {           //获取要更新的数据
            this.$http.get('client/findSingleClientById?id=' + this.rowId).then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.formData = res.data.data;
                    }
                }
            });
        },
        getLocationList() {     //区域数据
            let keyword = encodeURI('区域');
            this.$http.get('client/InformationByName?categoryName=' + keyword + '&systemId=0').then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.locationList = res.data.data;
                    }
                }
            });
        },
        getTradeList() {        //行业数据
            this.$http.get('industry/selectIndustryCategories').then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.tradeList = res.data.data;
                    }
                }
            });
        },
        getCustomerTypeList() {         //客户大类数据
            let keyword = encodeURI('客户大类');
            this.$http.get('client/findItemByName?categoryName=' + keyword).then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.customerTypeList = res.data.data;
                    }
                }
            });
        },
        getCustomerValueCategoryList() {        //客户价值分类
            let keyword = encodeURI('客户价值分类');
            this.$http.get('client/findItemByName?categoryName=' + keyword).then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.customerValueCategoryList = res.data.data;
                    }
                }
            });
        },
        getCustomerProductCategoryList() {        //客户产品分类
            let keyword = encodeURI('客户产品分类');
            this.$http.get('client/findItemByName?categoryName=' + keyword).then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.customerProductCategoryList = res.data.data;
                    }
                }
            });
        },
        getVatRatesList() {             //税率
            let keyword = encodeURI('税率');
            this.$http.get('client/InformationByName?categoryName=' + keyword + '&systemId=' + this.systemId).then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.vatRatesList = res.data.data;
                    }
                }
            });
        },
        getCountryList() {              //国家
            this.$http.get('city/findCountry').then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.countryList = res.data.data;
                        this.formData['locationCountryId'] = res.data.data[0]['id'];
                    }
                }
            });
        },
        getProvinceList(pid) {             //获取省份数据
            this.$http.get('city/findProvince?parentId=' + pid).then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.provinceList = res.data.data;
                    }
                }
            });
        },
        getCityList(pid) {                //获取城市数据
            this.$http.get('city/findCity?parentId=' + pid).then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.cityList = res.data.data;
                    }
                }
            });
        },
        getSaleMethodList() {               //销售方式数据
            let keyword = encodeURI('销售方式');
            this.$http.get('client/InformationByName?categoryName=' + keyword + '&systemId=' + this.systemId).then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.saleMethodList = res.data.data;
                    }
                }
            });
        },
        getFranchiseClerkList() {           //专营业务员
            this.$http.get('employee/findEmployeeByName?systemId=' + this.systemId).then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.franchiseClerkList = res.data.data;
                    }
                }
            });
        },
        getSettlementPeriodList() {         //结算期限
            let keyword = encodeURI('结算期限');      
            this.$http.get('client/InformationByName?categoryName=' + keyword + '&systemId=' + this.systemId).then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.settlementPeriodList = res.data.data;
                    }
                }
            });
        },
        showDepartment() {              //打开部门选择窗口
            this.$util.openLayerIframe({title: '客户资料-分管部门', zIndex: 13, width: '450px', height: '360px', url: this.$domain + '/#/basicData/customer/selectDepartment'});
        },
        toHomePage() {          //跳去公司主页
            if(this.formData['homepage']) {
                let url = this.formData['homepage'];
                if(url.substr(0, 7).toLowerCase() == "http://" || url.substr(0, 8).toLowerCase() == "https://") {
                    url = url;
                } else {
                    url = "http://" + url;
                }
                window.parent.open(url);
            }
        },
        save(formName) {            //保存
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    let data = {
                        mnemonicCode: this.formData['mnemonicCode'],        //助记码
                        name: this.formData['name'],        //名称
                        abbreviation: this.formData['abbreviation'],        //简称
                        address: this.formData['address'],          //客户地址
                        location: this.formData['location'],    //区域
                        trade: this.formData['trade'],          //行业
                        linkman: this.formData['linkman'],      //联系人
                        tel: this.formData['tel'],      //电话
                        fax: this.formData['fax'],      //传真
                        clientCategoryId: this.formData['clientCategoryId'],        //客户大类
                        customerValueCategory: this.formData['customerValueCategory'],      //客户价值分类
                        customerProductCategory: this.formData['customerProductCategory'],      //客户产品分类
                        accountNameOne: this.formData['accountNameOne'],        //开户名1
                        depositBankOne: this.formData['depositBankOne'],        //开户银行1
                        bankAccountOne: this.formData['bankAccountOne'],        //银行账号1
                        accountNameTwo: this.formData['accountNameTwo'],        //开户名2
                        depositBankTwo: this.formData['depositBankTwo'],        //开户银行2
                        bankAccountTwo: this.formData['bankAccountTwo'],        //银行账号2
                        accountNameThree: this.formData['accountNameThree'],    //开户名3
                        depositBankThree: this.formData['depositBankThree'],    //开户银行3
                        bankAccountThree: this.formData['bankAccountThree'],    //银行账号3
                        taxRedistrationNumber: this.formData['taxRedistrationNumber'],          //税务登记号
                        vatRates: this.formData['vatRates'],            //税率
                        locationCountryId: this.formData['locationCountryId'],            //所在国家(提交时是string类型)
                        locationProvinceId: this.formData['locationProvinceId'],           //所在省份(提交时是string类型)
                        locationCityId: this.formData['locationCityId'],               //所在城市(提交时是string类型)
                        homepage: this.formData['homepage'],        //公司主页
                        legalPersonRepresentative: this.formData['legalPersonRepresentative'],              //法人代表
                        saleMethod: this.formData['saleMethod'],            //销售方式
                        chargeDepartment: this.formData['chargeDepartment'],            //分管部门
                        franchiseClerk: this.formData['franchiseClerk'],            //专营业务员
                        creditAmount: this.formData['creditAmount'],            //信用额度
                        settlementPeriod: this.formData['settlementPeriod'],            //结算期限
                        remark: this.formData['remark'],             //备注
                        systemId: this.systemId,        //系统id
                    }
                    if(this.formData['id']) {
                        //修改
                        data['id'] = this.formData['id'];
                        this.$http({
                            url: 'client/updateClient',
                            method: 'post',
                            params: data
                        }).then(res => {
                            if(res.data.code == 20001) {
                                this.$message({message: '修改成功', type: 'success', duration: 1500});
                                this.$store.commit('customerStore/updateExpandNodeId', data['clientCategoryId']);           //根据客户大类来展开节点
                                setTimeout(() => {
                                    this.$store.dispatch('customerStore/getTreeData');      //刷新数据
                                    this.close();
                                }, 1000);
                            } else {
                                this.$message.error(res.data.msg || '修改失败');
                            }
                        });
                    } else {
                        //新增
                        this.$http({
                            url: 'client/insertClient',
                            method: 'post',
                            params: data
                        }).then(res => {
                            if(res.data.code == 20001) {
                                this.$message({message: '新增成功', type: 'success', duration: 1500});
                                this.$store.commit('customerStore/updateExpandNodeId', data['clientCategoryId']);           //根据客户大类来展开节点
                                setTimeout(() => {
                                    this.continueAdd ? this.$refs[formName].resetFields() : this.close();
                                    this.$store.dispatch('customerStore/getTreeData');      //刷新数据
                                }, 1000);
                            } else {
                                this.$message.error(res.data.msg || '新增失败');
                            }
                        });
                    }
                }
            });
        },
        close() {           //关闭新增弹窗
            let index = parent.layer.getFrameIndex(window.name);    //先得到当前iframe层的索引
            parent.layer.close(index);
        },
        enterKey(lastRef, nextRef) {		//回车键换行
            this.$refs[nextRef].focus();
        },
    },
    mounted() {
        this.getLocationList();
        this.getTradeList();
        this.getCustomerTypeList();
        this.getCustomerValueCategoryList();
        this.getCustomerProductCategoryList();
        this.getVatRatesList();
        this.getCountryList();
        this.getSaleMethodList();
        this.getFranchiseClerkList();
        this.getSettlementPeriodList();
        if(this.rowId) this.getUpdateData();
    }
}
</script>